<%@ page language="java" import="com.qipay.admin.utils.SiteHelper" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.baas.model.ActionDoc" %>
<%@ page import="com.qipay.baas.model.CpInfo" %>
<%@ page import="com.qipay.baas.model.User" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="com.qipay.baas.model.ActionDocDetail" %>
<!doctype html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/list.css">
    <script type="text/javascript">
        //document.getElementsByTagName("html")[0].style.width=screen.availWidth/100+"px";
        document.getElementsByTagName("html")[0].style.fontSize=screen.availWidth/200+"px";
    </script>
    <style type="text/css">
        .border{
            border:1px solid red;
        }
    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <% CpInfo cpInfo = (CpInfo) request.getAttribute("detail");%>
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">支付说明文档列表</h3>
                        </div>
                        <div>
                                <a class="btn btn-success"
                                   href="${pageContext.request.contextPath}/doc/child/add?did=<%= request.getParameter("did")%>">添加支付接口文档</a>
                                <button type="button" class="btn btn-default" onclick="window.history.back()">返回
                                </button>
                        </div>
                        <!-- /.box-header -->
                        <div class="tableContent">
                            <table width="100%" cellspacing="0" cellpadding="0" border="1">
                                <thead>
                                <tr>
                                    <th width="5%">ID</th>
                                    <th width="10%">标题</th>
                                    <th width="10%">类别</th>
                                    <th width="15%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <% List<ActionDocDetail> articles = (List<ActionDocDetail>) request.getAttribute("lst");
                                    User currentUser = (User) session.getAttribute("user");
                                    UserLevel userLevel = SiteHelper.getUserLevelByLevel(currentUser.getLevel());
                                    if (articles != null && articles.size() > 0) {
                                        Iterator<ActionDocDetail> iter = articles.iterator();
                                        ActionDocDetail user = null;
                                        while (iter.hasNext()) {
                                            user = iter.next();
                                %>
                                <tr id="user_<%=user.getId()%>">
                                    <td><%=user.getId()%>
                                    </td>
                                    <td><%= user.getTitle()%>
                                    </td>
                                    <td><%=user.getParntCateName()%>
                                    </td>
                                    <td>
                                        <% if (userLevel == UserLevel.ADMIN) {%>
                                        <a name="lnkDelete" pk="<%= user.getId()%>" href="javascript:remove(<%= user.getId()%>);">
                                            <button type="button" class="button back-red" style="font-size: 1rem">删除</button>
                                        </a>
                                        <%}%>

                                        <a href="${pageContext.request.contextPath}/doc/child/<%= user.getId()%>?did=<%= user.getDocId()%>">
                                            <button type="button" class="button back-green" style="font-size: 1rem">编辑</button></a>
                                    </td>
                                </tr>

                                <%
                                    }
                                } else {
                                %>
                                <tr>
                                    <td colspan="4">no data.</td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <jsp:include page="foot.jsp"></jsp:include>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.dataTables.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/dataTables.bootstrap.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.slimscroll.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>

    function remove(pk) {
        if (confirm("此项下的所有子文档都会删除，确定吗？")) {
            if (pk > 0) {
                $.ajax({
                    url: "${pageContext.request.contextPath}/ajax?n=deldocdetailbyid&id=" + pk,
                    type: "GET",
                    async: true,//true异步 false同步
                    context: this,
                    timeout: 10000,
                    success: function (data) {
                        if (data != null && data == "1") {
                            $("#user_" + pk).hide(100);
                        }
                        else {
                            alert("fail:" + data);
                        }
                    },
                    error: function (d, s, b) {
                        alert("失败:" + b);
                    }
                });
            }
        }
    }

    $(function () {
        $('#example2').DataTable({
            'paging': true,
            'lengthChange': false,
            'searching': false,
            'ordering': true,
            'info': true,
            'autoWidth': false
        });
//        $("[name='lnkDelete']").click(function () {
//            alert("12314234");
//            var pk = $(this).attr("pk");
//            remove(pk);
//        });
    })
</script>
</body>
</html>

